package cn.wubo.beetsql.service.impl;

import cn.wubo.beetsql.entity.Custom;
import cn.wubo.beetsql.service.ICustomService;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.SQLReady;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomServiceImpl implements ICustomService {
    @Autowired
    private SQLManager sqlManager;

    @Override
    public List<Custom> selectCustom(Custom custom) {
        return sqlManager.execute("select oo.message as name,mt.message as mes " +
                "from demo_table t,demo_onetoone oo,demo_onetomany om, demo_manytable mt " +
                "where t.id = oo.dtid and t.id = om.tid and om.mid = mt.id " +
                "and oo.message like #'%'+name+'%'#",Custom.class,custom);
    }

    @Override
    public List<Custom> selectCustomOther(Custom custom) {
        return sqlManager.execute(new SQLReady("select oo.message as name,mt.message as mes " +
                "from demo_table t,demo_onetoone oo,demo_onetomany om, demo_manytable mt " +
                "where t.id = oo.dtid and t.id = om.tid and om.mid = mt.id " +
                "and oo.message like ?","%" + custom.getName() + "%"),Custom.class);
    }
}
